<?php
    class test_Ajax extends Ajax
    {
        public function test()
        {
            echo 'lksdfkldskfdsklfsdkf';
            echo '<h1>name: '.$_POST['name'].'</h1>';
        }

        public function getData()
        {
            includeBlock('home/HotSP');
        }
        public function logout()
        {
            core::checkSession();
            $oDatabase = new database();
            $aCondition = array(
                'user_id = "'.$_SESSION['username'] => '"',

            );
            $aData = array(
                'online' => $_POST['status']    
            );
            $result = $oDatabase->update('user',$aData, $aCondition);
            unset($_SESSION['username']);
            unset($_SESSION['user_uri']);
            unset($_SESSION['image']);
            unset($_SESSION['browser']);
            unset($_SESSION['register']);
            unset($_SESSION['avatar']);
        }

        public function getcoment()
        {
            session_start();
            echo $_SESSION['username'];
        }

        public function getProduct()
        {
            $oDatabase = new database();
            $aListProduct = $oDatabase->getListObject("select * from product");
            if(count($aListProduct))
            {
                foreach($aListProduct as $key => $product)
                {
                    echo "<tr>";
                    echo "<td>".$product->product_id."</td>";
                    echo "<td>".$product->name."</td>";
                    echo "<td>".$product->total."</td>";
                    echo "</tr>";
                }
            }
        }
        public function addProduct()
        {
            $oDatabase = new database();
            $aData = array(
                'name' => $_POST['name'],
                'total' => $_POST['total']    
            );

            $result = $oDatabase->add('product',$aData); 
            if($result)
            {
                echo '<tr style="background-color:red;">';
                echo "<td>".$result."</td>";
                echo "<td>".$_POST['name']."</td>";
                echo "<td>".$_POST['total']."</td>";
                echo "</tr>";
            }
        }

        public function totalProduct()
        {
            $oDatabase = new database();
            echo $oDatabase->getValue("select count(*) from product"); 
        }

        public function deleteProduct()
        {
            $oDatabase = new database();
            $aCondition = array(
                'product_id = '.$_POST['id'] => '',

            );
            $result = $oDatabase->delete('product', $aCondition);
            if($result)
            {
                echo "OK";
            }
            else
            {
                echo $oDatabase->sSql;
            }
        }

        public function updateProduct()
        {
            $oDatabase = new database();
            $aCondition = array(
                'product_id = '.$_POST['id'] => '',

            );
            $aData = array(
                'name' => $_POST['name'],
                'total' => $_POST['total']    
            );

            $result = $oDatabase->update('product',$aData, $aCondition);
            if($result)
            {
                echo "OK";
            }
            else
            {
                echo $oDatabase->sSql;
            }
        }
        
        public function testJson()
        {
            $data = array(
                'name'=> 'trieu quang phuc',
                'tuoi' => '32',
                'sdt' => '34345435435',
                'image' => array(
                    '1'=>'hekklsdfljksdfksdlkfel',
                    '2'=>'hekklsdfljksdfksdlkfel',
                    '3'=>'hekklsdfljksdfksdlkfel',
                    '4'=>'hekklsdfljksdfksdlkfel',
                    '5'=>'hekklsdfljksdfksdlkfel',
                    '6'=>'hekklsdfljksdfksdlkfel',
                    '7'=>'hekklsdfljksdfksdlkfel',
                    '8'=>'hekklsdfljksdfksdlkfel',
                ),
            );
            echo json_encode($data);
        }
    }
?>
